import 'package:flutter/material.dart';
import 'package:mobile_app.core/core/presentation/theme/styles.dart';

part 'styles.dart';

part 'text_theme.dart';

class LearningPageTheme extends InheritedTheme {
  LearningPageTheme({
    required Brightness brightness,
    required super.child,
    super.key,
  })  : _brightness = brightness,
        _data = _buildThemeData(
          brightness: brightness,
        );

  final Brightness _brightness;
  final LearningPageThemeData _data;

  static LearningPageThemeData _buildThemeData({
    required Brightness brightness,
  }) {
    return switch (brightness) {
      Brightness.dark => LearningPageThemeData.dark(),
      Brightness.light => LearningPageThemeData.light(),
    };
  }

  static LearningPageThemeData of(BuildContext context) {
    final inheritedTheme = context.dependOnInheritedWidgetOfExactType<LearningPageTheme>()!;
    return inheritedTheme._data;
  }

  @override
  Widget wrap(BuildContext context, Widget child) {
    final ancestorTheme = context.findAncestorWidgetOfExactType<LearningPageTheme>();

    if (identical(this, ancestorTheme)) {
      return child;
    }

    return LearningPageTheme(
      brightness: _brightness,
      child: child,
    );
  }

  @override
  bool updateShouldNotify(LearningPageTheme oldWidget) {
    return _brightness != oldWidget._brightness;
  }
}

class LearningPageThemeData {
  const LearningPageThemeData._internal({
    required this.textTheme,
  });

  factory LearningPageThemeData.light() {
    return LearningPageThemeData._internal(
      textTheme: LearningPageTextTheme.light(),
    );
  }

  factory LearningPageThemeData.dark() {
    return LearningPageThemeData._internal(
      textTheme: LearningPageTextTheme.dark(),
    );
  }

  final LearningPageTextTheme textTheme;
}
